home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / README.oldforeign < prev    next >
Encoding:
Text File  |  1996-01-22  |  2.6 KB  |  80 lines

  1.           Using old-style foreign code with SWI-Prolog 2.5
  2.  
  3.  
  4. 1.  Introduction
  5. ================
  6.  
  7. The foreign language interface  has   been  changed  drastically between
  8. version 2.1.14 and 2.5.0 (there are no intermediate releases). This file
  9. describes some considerations for converting old code.
  10.  
  11.  
  12. 2.  Rewrite your interface?
  13. ===========================
  14.  
  15. If you have only a small porting of   C, you can consider rewriting your
  16. interface. The new code will generally run   faster,  is easier to write
  17. and read and your code again be  compatible with many future releases of
  18. SWI-Prolog. In addition, it will be much   easier  to run your code with
  19. Quintus or SICStus Prolog (basically  declare   the  type as `+term' and
  20. write macros to deal with the different   names  of the functions in all
  21. three Prolog systems).
  22.  
  23. Below are some example code fragments and their translation:
  24.  
  25. READING ARGUMENTS
  26. ****************************************************************
  27. { if ( PL_is_integer(x) )
  28.   { long n = PL_integer_value(PL_atomic(x));
  29.     
  30.     ...
  31. ================================================================
  32. { long n;
  33.  
  34.   if ( PL_get_long(x, &n) )
  35.   { ...
  36. ****************************************************************
  37.  
  38. WRITING ARGUMENTS
  39. ****************************************************************
  40. pl_get_something(term x)
  41. { char *answer = getsomething();
  42.  
  43.   return PL_unify_atomic(x, PL_new_atom(answer));
  44. }
  45. ================================================================
  46. pl_get_something(term x)
  47. { char *answer = getsomething();
  48.  
  49.   return PL_unify_atom_chars(x, answer);
  50. }
  51. ****************************************************************
  52.  
  53.  
  54. 3. Using backward compatibility feature
  55. =======================================
  56.  
  57. Alternatively, you may decide to use the backward compatibility flag:
  58.  
  59. #define PL_OLD_INTERFACE
  60. #include <SWI-Prolog.h>
  61.  
  62. You can NOT mix old and new code in the same file (but Prolog can handle
  63. object-files holding both old and new code).
  64.  
  65. You can expect  a  number  of   warning  from  your  compiler.  Notably,
  66. PL_new_atom() used to return an unsigned long, while it returns a void *
  67. in the new interface.
  68.  
  69. Using the backward compatibility feature is   not  entirely safe against
  70. garbage-collection,  at  least  not  when    the  garbage-collector  and
  71. stack-shifter will be complete. Notably the  `atomic' handles of strings
  72. can be invalidated by a stack-shift or garbage collection.
  73.  
  74. The new interface PL_put_*()  functions  allow   for  the  reuse of term
  75. references. In the old code, PL_arg(),  etc. create a new term-reference
  76. for each argument extracted.
  77.  
  78. PL_call_predicate() is only available with  the new calling conventions.
  79. PL_call() based callback will work.
  80.